import { lib, game, ui, get, ai, _status } from "../../../noname.js";
export default {
    translate: {
        "DALF_card_dongyu": "冻雨",
        "DALF_card_dongyu_info": "出牌阶段，对一名角色使用。目标角色在判定阶段判定后，若结果为♠，其弃置一张牌。",

        "DALF_card_forward": "前进",
        "DALF_card_forward_info": "出牌阶段，对含你在内的一名角色使用。令目标角色装备区中的〔王国宝物〕点数+1（若为2则改为+2），然后进行一次升变检定。",
        "DALF_card_usurp": "夺位",
        "DALF_card_usurp_info": "出牌阶段，对一名可以拼点、且〔王国宝物〕点数大于A的其他角色使用。与其各摸一张牌并拼点，若你赢，你的〔王国宝物〕点数+1且其的-1，若你的〔王国宝物〕点数为A则改为交换点数；最后你与其各进行升变检定与降格检定。",
        "DALF_card_nothing": "空无",
        "DALF_card_nothing_info": "<li>①锁定技，当你装备此牌时，创建四张【前进】和一张【夺位】洗入牌堆，然后摸一张牌。</li><br><li>②锁定技，摸牌阶段，你少摸一张牌并从牌堆中随机获得一张【前进】或【夺位】。</li><br><li>③锁定技，每回合限一次，你进入濒死时，回复1点体力。</li>",
        "DALF_card_pawn": "士兵",
        "DALF_card_pawn_info": "<li>①出牌阶段限一次，若有其他角色的〔王国宝物〕点数与你的差值不大于1，你可以将两张手牌当任意伤害类即时牌对其使用，然后你创建并获得一张【前进】。</li><br><li>②锁定技，你累计受到2点伤害后，回复1点体力，此牌点数-1并进行一次降格检定。</li>",
        "DALF_card_pawn_1": "士兵攻击",
        "DALF_card_pawn_2": "士兵后退",
        "DALF_card_bishop": "主教",
        "DALF_card_bishop_info": "<li>①锁定技，你的【前进】视为【无懈可击】且不计入手牌上限，且每一张【前进】使你手牌上限+1。</li><br><li>②锁定技，摸牌阶段，你选择执行〖涉猎〗或〖好施〗的效果。</li><br><li>③锁定技，你进入濒死时回复体力至1点，此牌降格为♠2【士兵】。</li>",
        "DALF_card_bishop_1": "主教宣告",
        "DALF_card_bishop_2": "主教开济",
        "DALF_card_bishop_3": "主教降格",
        "DALF_card_knight": "骑士",
        "DALF_card_knight_info": "<li>①锁定技，你的【前进】视为【闪】且不计入手牌上限，且抵消【杀】后使用此【杀】。</li><br><li>②锁定技，你的防御距离+1，你对攻击范围内没有你的角色使用牌无距离限制。</li><br><li>③锁定技，你进入濒死时回复体力至1点，此牌降格为♠2【士兵】。</li>",
        "DALF_card_knight_1": "骑士礼仪",
        "DALF_card_knight_2": "骑士转进",
        "DALF_card_knight_3": "骑士降格",
        "DALF_card_rook": "城堡",
        "DALF_card_rook_info": "<li>①锁定技，你不能使用【前进】且获得此牌时弃置之并获得1点护甲；若你有护甲，你的攻击范围与手牌上限+3。</li><br><li>②锁定技，你进入濒死时回复体力至1点，此牌降格为♠5【士兵】。</li>",
        "DALF_card_rook_1": "城堡叠甲",
        "DALF_card_rook_2": "城堡降格",
        "DALF_card_prince": "亲王",
        "DALF_card_prince_info": "<li>①锁定技，你不能使用【前进】。</li><br><li>②出牌阶段，你可以弃置一张【前进】并摸一张牌，从牌堆中获得一张指定颜色与类别的牌。</li><br><li>③锁定技，你进入濒死时回复体力至2点，此牌降格为♠5【士兵】。</li>",
        "DALF_card_prince_1": "亲王之缚",
        "DALF_card_prince_2": "亲王权能",
        "DALF_card_prince_3": "亲王降格",
        "DALF_card_queen": "女王",
        "DALF_card_queen_info": "<li>①锁定技，你不能使用【前进】；场上每有一张点数大于7的〔王国宝物〕你的手牌上限和摸牌阶段摸牌数+1。</li><br><li>②你可以将【前进】当除全体锦囊外任意主动即时牌使用。</li><br><li>③锁定技，你进入濒死时回复体力至2点，然后此牌降格为♠5【士兵】。</li>",
        "DALF_card_queen_1": "女王之缚",
        "DALF_card_queen_2": "女王权能",
        "DALF_card_queen_3": "女王降格",
        "DALF_card_queen2": "白王",
        "DALF_card_queen2_info": "<li>①锁定技，若此牌点数大于7，你不能使用【前进】；场上每有一张点数大于7的〔王国宝物〕你的手牌上限和摸牌阶段摸牌数+1。</li><br><li>②你可以将【前进】当除全体锦囊外任意主动即时牌使用。</li><br><li>③每两轮限一次，你进入濒死时，可以回复体力至2点。</li>",
        "DALF_card_queen2_1": "白王之缚",
        "DALF_card_queen2_3": "白王再起",
        "DALF_card_king": "国王",
        "DALF_card_king_info": "<li>①锁定技，你不能使用【前进】，【夺位】不会使此牌点数-1；每累计两张【前进】离开一名角色手牌区，你摸一张牌。</li><br><li>②出牌阶段限三次，你可以重铸一张【前进】，然后创建两张【前进】洗入牌堆。</li><br><li>③锁定技，你进入濒死时回复所有体力，此牌降格为♠1【空无】，然后摸一张牌并与所有【王子】装备者同时拼点，其中赢且点数最大的“亲王”升变为♠K【国王】。</li>",
        "DALF_card_king_1": "国王之缚",
        "DALF_card_king_2": "国王权能",
    },
    card: {
        "DALF_card_dongyu": {
            image: "ext:约会大作战/image/card/DALF_card_dongyu.png",
            fullskin: true,
            type: "delay",
            filterTarget: function (card, player, target) {
                return lib.filter.judge(card, player, target);
            },
            judge: function (card) {
                return get.suit(card) == 'spade' ? -0.5 : 0;
            },
            effect: function () {
                if (result.bool == false) {
                    player.chooseToDiscard('he', true);
                }
            },
            ai: {
                basic: {
                    order: 1,
                    useful: 1,
                    value: -0.5
                },
                result: {
                    target: -1
                },
                tag: { discard: 1 }
            }
        },

        "DALF_card_forward": {
            image: "ext:约会大作战/image/card/DALF_card_forward.png",
            fullskin: true,
            type: "basic",
            enable: true,
            filterTarget: function (card, player, target) {
                if (ui.selected.targets.includes(player)) return true;
                return target == player;
            },
            content: function () {
                "step 0"
                let card2 = target.storage['DALF_KingdomTreasure'];
                if (card2 && typeof card2.number == 'number' && card2.number < 13) {
                    if (card2.number == 2) card2.number += 1;
                    card2.number += 1;
                }
                if (!target.hasCard(function (cardx) {
                    return cardx == card2;
                }, 'e')) {
                    if (target.countEnabledSlot('equip5') < 1)
                        target.expandEquip(5);
                    target.equip(card2);
                }
                "step 1"
                var next = game.createEvent('DALF_KingdomTreasure_upgrade', false);
                next.player = target;
                next.card = target.storage['DALF_KingdomTreasure'];
                next.setContent(lib.skill['DALF_KingdomTreasure_upgrade'].content);
            },
            ai: {
                basic: {
                    order: 10,
                    useful: 4,
                    value: function (card, player) {
                        let card2 = player.storage['DALF_KingdomTreasure'];
                        if (card2 && get.number(card2) < 8) return [5.3, 5];
                        return [7.3, 6.8, 5];
                    }
                },
                result: {
                    target: function (player, target) {
                        if (target == player) return 1.5;
                        let card = target.storage['DALF_KingdomTreasure'];
                        if (card && get.number(card) < 8) return 1;
                        return 0;
                    }
                },
                tag: {}
            }
        },
        "DALF_card_usurp": {
            image: "ext:约会大作战/image/card/DALF_card_usurp.png",
            fullskin: true,
            type: "trick",
            enable: true,
            filter: function (event, player) {
                if (!player.storage['DALF_KingdomTreasure']) return false;
                return true;
            },
            filterTarget: function (card, player, target) {
                if (!player.canCompare(target)) return false;
                return target.storage['DALF_KingdomTreasure'] &&
                    target.storage['DALF_KingdomTreasure'].number > 1;
            },
            content: function () {
                "step 0"
                game.asyncDraw([player, target], 1);
                player.chooseToCompare(target);
                "step 1"
                if (result.bool) {
                    let card1 = player.storage['DALF_KingdomTreasure'],
                        card2 = target.storage['DALF_KingdomTreasure'];
                    if (card1 && card2) {
                        if (card1.number == 1) {
                            let temp = card1.number;
                            card1.number = card2.number;
                            card2.number = temp;
                        } else {
                            card1.number = Math.min(card1.number + 1, 13);
                            if (card2.name != 'DALF_card_king')
                                card2.number = Math.max(card2.number - 1, 1);
                        }
                        var next1 = game.createEvent('DALF_KingdomTreasure_upgrade', false);
                        next1.player = player;
                        next1.card = player.storage['DALF_KingdomTreasure'];
                        next1.setContent(lib.skill['DALF_KingdomTreasure_upgrade'].content);
                        var next2 = game.createEvent('DALF_KingdomTreasure_relegate', false);
                        next2.player = target;
                        next2.card = target.storage['DALF_KingdomTreasure'];
                        next2.setContent(lib.skill['DALF_KingdomTreasure_relegate'].content);
                    }
                }
            },
            ai: {
                basic: {
                    order: 3.7,
                    useful: 7,
                    value: function (card, player) {
                        let card2 = player.storage['DALF_KingdomTreasure'];
                        if (card2 && get.number(card2) == 1) return [6, 3, 0.5];
                        return [5.5, 5, 0.5];
                    }
                },
                result: {
                    target: function (player, target) {
                        return -5 / Math.max(target.countCards('h'), 1);
                    }
                },
                tag: {}
            }
        },
        "DALF_card_nothing": {
            image: "ext:约会大作战/image/card/DALF_card_nothing.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_nothing_1", "DALF_card_nothing_2", "DALF_card_nothing_3"],
            ai: {
                basic: {
                    equipValue: 8
                }
            }
        },
        "DALF_card_pawn": {
            image: "ext:约会大作战/image/card/DALF_card_pawn.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_pawn_1", "DALF_card_pawn_2"],
            ai: {
                basic: {
                    equipValue: 6
                }
            }
        },
        "DALF_card_bishop": {
            image: "ext:约会大作战/image/card/DALF_card_bishop.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_bishop_1", "DALF_card_bishop_2", "DALF_card_bishop_3"],
            ai: {
                basic: {
                    equipValue: 8
                }
            }
        },
        "DALF_card_knight": {
            image: "ext:约会大作战/image/card/DALF_card_knight.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_knight_1", "DALF_card_knight_2", "DALF_card_knight_3"],
            ai: {
                basic: {
                    equipValue: 8
                }
            }
        },
        "DALF_card_rook": {
            image: "ext:约会大作战/image/card/DALF_card_rook.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_rook_1", "DALF_card_rook_2"],
            ai: {
                basic: {
                    equipValue: 10
                }
            }
        },
        "DALF_card_prince": {
            image: "ext:约会大作战/image/card/DALF_card_prince.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_prince_1", "DALF_card_prince_2", "DALF_card_prince_3"],
            ai: {
                basic: {
                    equipValue: 10
                }
            }
        },
        "DALF_card_queen": {
            image: "ext:约会大作战/image/card/DALF_card_queen.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_queen_1", "DALF_card_queen_2", "DALF_card_queen_3"],
            ai: {
                basic: {
                    equipValue: 14
                }
            }
        },
        "DALF_card_queen2": {
            image: "ext:约会大作战/image/card/DALF_card_queen2.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_queen2_1", "DALF_card_queen_2", "DALF_card_queen2_3"],
            ai: {
                basic: {
                    equipValue: 16
                }
            }
        },
        "DALF_card_king": {
            image: "ext:约会大作战/image/card/DALF_card_king.png",
            fullskin: true,
            type: "equip",
            subtype: "equip5",
            skills: ["DALF_card_king_1", "DALF_card_king_2", "DALF_card_king_3"],
            ai: {
                basic: {
                    equipValue: 9
                }
            }
        },
    },
    skill: {
        "DALF_card_nothing_1": {
            equipSkill: true,
            trigger: { player: "equipAfter" },
            forced: true,
            filter: function (event, player) {
                return event.card.name == 'DALF_card_nothing';
            },
            content: function () {
                "step 0"
                var cards = [];
                for (let i = 0; i < 5; i++) {
                    let name = (i) ? 'DALF_card_forward' : 'DALF_card_usurp';
                    cards.push(game.createCard2(name));
                    var p = Math.floor(Math.random() * ui.cardPile.childElementCount);
                    ui.cardPile.insertBefore(cards[i], ui.cardPile.childNodes[p]);
                }
                player.$throw(cards, 100);
                "step 1"
                player.draw();
            }
        },
        "DALF_card_nothing_2": {
            equipSkill: true,
            trigger: { player: "phaseDrawBegin2" },
            forced: true,
            filter: function (event, player) {
                return !event.numFixed && event.num > 0;
            },
            content: function () {
                "step 0"
                trigger.num--;
                var cardx = get.cardPile2(function (cardi) {
                    return ['DALF_card_forward', 'DALF_card_usurp'].includes(cardi.name);
                });
                if (cardx) player.gain(cardx, 'draw2');
            }
        },
        "DALF_card_nothing_3": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            usable: 1,
            content: function () {
                "step 0"
                player.recover();
            }
        },
        "DALF_card_pawn_1": {
            equipSkill: true,
            enable: "phaseUse",
            usable: 1,
            filter: function (event, player) {
                if (!player.storage['DALF_KingdomTreasure']) return false;
                if (player.countCards('hes') < 2) return false;
                return game.hasPlayer(function (current) {
                    if (current == player || !current.storage['DALF_KingdomTreasure']) return false;
                    return Math.abs(player.storage['DALF_KingdomTreasure'].number -
                        current.storage['DALF_KingdomTreasure'].number) <= 1;
                });
            },
            hiddenCard: function (player, name) {
                if (!game.hasPlayer(function (current) {
                    if (current == player || !current.storage['DALF_KingdomTreasure']) return false;
                    return Math.abs(player.storage['DALF_KingdomTreasure'].number -
                        current.storage['DALF_KingdomTreasure'].number) <= 1;
                })) return false;
                return get.tag({ name: name }, 'damage');
            },
            chooseButton: {
                dialog: function (event, player) {
                    var list = [];
                    for (let i of lib.inpile) {
                        let cardx = { name: i };
                        if (!get.tag(cardx, 'damage')) continue;
                        let info = get.info(cardx);
                        if (!info || !info.enable) continue;
                        if (get.is.instantCard(cardx))
                            list.push([get.type(cardx), '', i])
                    }
                    return ui.create.dialog('士兵', [list, 'vcard']);
                },
                filter: function (button, player) {
                    return lib.filter.filterCard({ name: button.link[2] }, player, _status.event.getParent());
                },
                check: function (button) {
                    let player = _status.event.player;
                    let players = game.filterPlayer(function (current) {
                        if (current == player || !current.storage['DALF_KingdomTreasure']) return false;
                        return Math.abs(player.storage['DALF_KingdomTreasure'].number -
                            current.storage['DALF_KingdomTreasure'].number) <= 1;
                    }),
                        eff = 0,
                        cardx = { name: button.link[2] };
                    for (let i = 0; i < players.length; i++) {
                        if (!player.canUse(cardx, players[i], true, true)) continue;
                        eff = Math.max(get.effect(players[i], cardx, player, player), eff);
                    }
                    return eff + eff * (Math.random() - 0.5) * 0.5;
                },
                backup: function (links, player) {
                    return {
                        filterCard: true,
                        selectCard: 2,
                        position: "hs",
                        popname: true,
                        viewAs: { name: links[0][2] },
                        check: function (card) {
                            return 7 - get.value(card);
                        },
                        filterTarget: function (card, player, target) {
                            if (target == player || !target.storage['DALF_KingdomTreasure']) return false;
                            if (Math.abs(player.storage['DALF_KingdomTreasure'].number -
                                target.storage['DALF_KingdomTreasure'].number) > 1)
                                return false;
                            if (!card) card = get.card();
                            return lib.filter.targetEnabled2.apply(this, arguments);
                        },
                        onuse: function (result, player) {
                            var next = game.createEvent('DALF_card_pawn_1_draw');
                            _status.event.next.remove(next);
                            _status.event.after.push(next);
                            next.player = player;
                            next.setContent(function () {
                                "step 0"
                                let cardx = game.createCard2('DALF_card_forward');
                                player.gain(cardx, 'draw2');
                            });
                        }
                    };
                },
                prompt: function (links, player) {
                    return '将两张牌当作【' + get.translation(links[0][2]) + '】使用';
                }
            },
            ai: {
                order: 7,
                result: {
                    player: 1
                }
            }
        },
        "DALF_card_pawn_2": {
            equipSkill: true,
            trigger: { player: "damageEnd" },
            forced: true,
            silent: true,
            content: function () {
                "step 0"
                player.storage['DALF_card_pawn_2'] += trigger.num;
                if (player.storage['DALF_card_pawn_2'] >= 2) {
                    let card = player.storage['DALF_KingdomTreasure'];
                    if (card != undefined) {
                        do {
                            player.storage['DALF_card_pawn_2'] -= 2
                            player.recover();
                            card.number = Math.max(card.number - 1, 1);
                        } while (player.storage['DALF_card_pawn_2'] >= 2);
                        if (!player.hasSkill('DALF_luanzhou')) {
                            player.logSkill('DALF_card_pawn_2');
                            var next2 = game.createEvent('DALF_KingdomTreasure_relegate', false);
                            next2.player = player;
                            next2.card = card;
                            next2.setContent(lib.skill['DALF_KingdomTreasure_relegate'].content);
                        }
                        if (card.number > 1) card.init(card);
                    }
                }
            }
        },
        "DALF_card_bishop_1": {
            equipSkill: true,
            mod: {
                cardname: function (card) {
                    if (card.name == 'DALF_card_forward')
                        return 'wuxie';
                },
                ignoredHandcard: function (card, player) {
                    if (card.name == 'DALF_card_forward')
                        return true;
                },
                cardDiscardable: function (card, player, name) {
                    if (name == 'phaseDiscard' && card.name == 'DALF_card_forward')
                        return false;
                },
                maxHandcard: function (player, num) {
                    return num + player.countCards('h', { name: 'DALF_card_forward' });
                }
            }
        },
        "DALF_card_bishop_2": {
            equipSkill: true,
            trigger: { player: ["phaseDrawBegin1", "phaseDrawBegin2"] },
            forced: true,
            filter: function (event, player, onrewrite) {
                if (onrewrite == 'phaseDrawBegin1')
                    return !event.numFixed;
                return event.DALF_card_bishop_2;
            },
            content: function () {
                "step 0"
                if (event.triggername == 'phaseDrawBegin1') {
                    var next = player.chooseControl(['shelie', 'haoshi']);
                    next.set('choiceList', [
                        '<b>' + lib.translate['shelie'] + '</b>：' + lib.translate['shelie_info'],
                        '<b>' + lib.translate['haoshi'] + '</b>：' + lib.translate['haoshi_info']
                    ]);
                    next.set('prompt', '选择一个你要执行的技能效果：');
                    next.set('ai', function () {
                        if (player.countCards('h') <= 1) return list[1];
                        return game.hasPlayer(function (current) {
                            return current != player &&
                                current.isMinHandcard() &&
                                get.attitude(player, current) > 0;
                        }) ? list[1] : list[0];
                    });
                } else {
                    delete trigger.numFixed;
                    player.logSkill('haoshi');
                    trigger.num += 2;
                    player.addSkill('haoshi2');
                    event.finish();
                }
                "step 1"
                if (result.control == 'haoshi') {
                    trigger.numFixed = true;
                    trigger.DALF_card_bishop_2 = true;
                    event.finish();
                }
                "step 2"
                player.logSkill('shelie');
                trigger.changeToZero();
                event.cards = get.cards(5);
                game.cardsGotoOrdering(event.cards);
                event.videoId = lib.status.videoId++;
                game.broadcastAll(function (player, id, cards) {
                    let str = '涉猎';
                    if (player == game.me && !_status.auto) {
                        str += '：获取花色各不相同的牌';
                    }
                    let dialog = ui.create.dialog(str, cards);
                    dialog.videoId = id;
                }, player, event.videoId, event.cards);
                event.time = get.utc();
                game.addVideo('showCards', player, ['涉猎', get.cardsInfo(event.cards)]);
                game.addVideo('delay', null, 2);
                "step 3"
                let list = [];
                for (let i of cards) list.add(get.suit(i, false));
                var next = player.chooseButton(list.length, true);
                next.set('dialog', event.videoId);
                next.set('filterButton', function (button) {
                    for (let i = 0; i < ui.selected.buttons.length; i++) {
                        if (get.suit(ui.selected.buttons[i].link) == get.suit(button.link)) return false;
                    }
                    return true;
                });
                next.set('ai', function (button) {
                    return get.value(button.link, _status.event.player);
                });
                "step 4"
                if (result.bool && result.links) {
                    event.cards2 = result.links;
                } else {
                    event.finish();
                }
                let time = 1000 - (get.utc() - event.time);
                if (time > 0) {
                    game.delay(0, time);
                }
                "step 5"
                game.broadcastAll('closeDialog', event.videoId);
                let cards2 = event.cards2;
                player.gain(cards2, 'log', 'gain2');
            }
        },
        "DALF_card_bishop_3": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            content: function () {
                "step 0"
                event.cardx = player.storage['DALF_KingdomTreasure'];
                let num = 1 - player.hp;
                if (num > 0) player.recover(num);
                if (!player.hasSkill('DALF_luanzhou')) {
                    event.isRelegate = true;
                    if (event.cardx != undefined) {
                        let num = event.cardx.storage.gainMaxHp - 1;
                        event.cardx.name = 'DALF_card_pawn';
                        event.cardx.number = 2;
                        event.cardx.storage.gainMaxHp = 1;
                        if (num > 0) player.loseMaxHp(num);
                        game.log(player, '的', '#g【主教】', '降格为了', '#g【士兵】');
                    }
                }
                "step 1"
                if (event.isRelegate && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.finish();
                card.init(card);
                "step 2"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    player.equip(event.cardx);
                }
            }
        },
        "DALF_card_knight_1": {
            equipSkill: true,
            mod: {
                cardname: function (card) {
                    if (card.name == 'DALF_card_forward')
                        return 'shan';
                },
                ignoredHandcard: function (card, player) {
                    if (card.name == 'DALF_card_forward')
                        return true;
                },
                cardDiscardable: function (card, player, name) {
                    if (name == 'phaseDiscard' && card.name == 'DALF_card_forward')
                        return false;
                }
            },
            trigger: { player: "useCard" },
            direct: true,
            filter: function (event, player) {
                if (event.card.name != 'shan') return false;
                if (!event.cards || !event.cards.length ||
                    !event.cards[0] != 'DALF_card_forward')
                    return false;
                if (!event.respondTo) return false;
                if (!event.respondTo[1].cards)
                    return true;
                return event.respondTo[1].cards.length -
                    event.respondTo[1].cards.filterInD('od').length == 0;
            },
            content: function () {
                "step 0"
                var next = player.chooseUseTarget(trigger.respondTo[1]);
                next.set('prompt', '主教：你可以使用你响应的' + get.translation(trigger.respondTo[1]));
            }
        },
        "DALF_card_knight_2": {
            equipSkill: true,
            mod: {
                globalTo: function (from, to, distance) {
                    return distance + 1;
                },
                targetInRange: function (card, player, target) {
                    if (!target.inRange(player)) return true;
                }
            }
        },
        "DALF_card_knight_3": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            content: function () {
                "step 0"
                event.cardx = player.storage['DALF_KingdomTreasure'];
                let hp = 1 - player.hp;
                if (hp > 0) player.recover(hp);
                if (!player.hasSkill('DALF_luanzhou')) {
                    event.isRelegate = true;
                    if (event.cardx != undefined) {
                        let maxHp = event.cardx.storage.gainMaxHp - 1;
                        event.cardx.name = 'DALF_card_pawn';
                        event.cardx.number = 2;
                        event.cardx.storage.gainMaxHp = 1;
                        if (maxHp > 0) player.loseMaxHp(maxHp);
                        game.log(player, '的', '#g【骑士】', '降格为了', '#g【士兵】');
                    }
                }
                "step 1"
                if (event.isRelegate && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.finish();
                card.init(card);
                "step 2"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    player.equip(event.cardx);
                }
            }
        },
        "DALF_card_rook_1": {
            equipSkill: true,
            mod: {
                attackRange: function (player, num) {
                    if (player.hujia) return num + 3;
                },
                maxHandcard: function (player, num) {
                    if (player.hujia) return num + 3;
                },
                cardEnabled: function (card) {
                    if (card.name == 'DALF_card_forward') return false;
                }
            },
            trigger: { player: "gainEnd" },
            forced: true,
            filter: function (event, player) {
                return event.cards.some(card => get.name(card) == 'DALF_card_forward');
            },
            content: function () {
                "step 0"
                let cards = trigger.cards.filter(card => get.name(card) == 'DALF_card_forward');
                if (cards.length) {
                    player.discard(cards);
                    player.changeHujia(cards.length);
                }
            }
        },
        "DALF_card_rook_2": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            content: function () {
                "step 0"
                event.cardx = player.storage['DALF_KingdomTreasure'];
                let hp = 1 - player.hp;
                if (hp > 0) player.recover(hp);
                if (!player.hasSkill('DALF_luanzhou')) {
                    event.isRelegate = true;
                    if (event.cardx != undefined) {
                        let maxHp = event.cardx.storage.gainMaxHp - 1;
                        event.cardx.name = 'DALF_card_pawn';
                        event.cardx.number = 5;
                        event.cardx.storage.gainMaxHp = 1;
                        if (maxHp > 0) player.loseMaxHp(maxHp);
                        game.log(player, '的', '#g【城堡】', '降格为了', '#g【士兵】');
                    }
                }
                "step 1"
                if (event.isRelegate && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.finish();
                card.init(card);
                "step 2"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    player.equip(event.cardx);
                }
            }
        },
        "DALF_card_prince_1": {
            equipSkill: true,
            mod: {
                cardEnabled: function (card) {
                    if (card.name == 'DALF_card_forward') return false;
                }
            }
        },
        "DALF_card_prince_2": {
            equipSkill: true,
            enable: "phaseUse",
            filter: function (event, player) {
                return player.hasCard(function (card) {
                    return get.name(card) == 'DALF_card_forward';
                }, 'h');
            },
            filterCard: { name: "DALF_card_forward" },
            check: () => 1,
            content: function () {
                "step 0"
                player.draw();
                "step 1"
                let list = ['black', 'red', 'basic', 'trick', 'equip'];
                for (let i = 0; i < list.length; i++) {
                    list[i] = [list[i], get.translation(list[i]) + '牌'];
                }
                let next = player.chooseButton([
                    '亲王：请选择要获得牌的颜色与类别', [list.slice(0, 2), 'tdnodes'],
                    [list.slice(2), 'tdnodes']
                ]);
                next.set('forced', true);
                next.set('selectButton', 2);
                next.set('filterButton', function (button) {
                    if (ui.selected.buttons.length) {
                        if (['red', 'black'].includes(ui.selected.buttons[0].link))
                            return !['red', 'black'].includes(button.link);
                        return false;
                    }
                    return ['red', 'black'].includes(button.link);
                });
                next.set('list', list);
                next.set('ai', function (button) {
                    let player = _status.event.player;
                    if (ui.selected.buttons.length) {
                        let color = ui.selected.buttons[0].link;
                        switch (button.link) {
                            case 'basic':
                                {
                                    if (color == 'red') {
                                        if (player.getDamagedHp())
                                            return 1.2;
                                    } else if (!player.hasSha()) return 1;
                                    return 0;
                                }
                            case 'trick':
                                {
                                    return Math.random() + (color == 'red' ? 0.8 : 0.4);
                                }
                            case 'equip':
                                {
                                    if (player.countCards('e') < 3) return 1.3;
                                }
                            default:
                                return Math.random() - 0.1;
                        }
                    } else switch (button.link) {
                        case 'red':
                            return Math.random() + 0.2;
                        case 'black':
                            return Math.random();
                        default:
                            return 0;
                    }
                });
                "step 1"
                let color = result.links[0],
                    type = result.links[1];
                let cardx = get.cardPile2(function (c) {
                    return get.color(c) == color && get.type2(c) == type;
                });
                if (cardx) player.gain(cardx, 'draw');
            }
        },
        "DALF_card_prince_3": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            silent: true,
            content: function () {
                "step 0"
                event.cardx = player.storage['DALF_KingdomTreasure'];
                let hp = 2 - player.hp;
                if (hp > 0) player.recover(hp);
                if (!player.hasSkill('DALF_luanzhou')) {
                    event.isRelegate = true;
                    if (event.cardx != undefined) {
                        let maxHp = event.cardx.storage.gainMaxHp - 1;
                        event.cardx.name = 'DALF_card_pawn';
                        event.cardx.number = 5;
                        event.cardx.storage.gainMaxHp = 1;
                        if (maxHp > 0) player.loseMaxHp(maxHp);
                        game.log(player, '的', '#g【亲王】', '降格为了', '#g【士兵】');
                    }
                }
                "step 1"
                if (event.isRelegate && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.finish();
                card.init(card);
                "step 2"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    player.equip(event.cardx);
                }
            }
        },
        "DALF_card_queen_1": {
            equipSkill: true,
            mod: {
                cardEnabled: function (card) {
                    if (card.name == 'DALF_card_forward') return false;
                },
                maxHandcard: function (player, num) {
                    return num + game.countPlayer(function (current) {
                        return current.storage['DALF_KingdomTreasure'].number > 7;
                    });
                }
            },
            trigger: {
                player: "phaseDrawBegin2"
            },
            forced: true,
            silent: true,
            filter: function (event, player) {
                return !event.numFixed;
            },
            content: function () {
                "step 0"
                trigger.num += game.countPlayer(function (current) {
                    return current.storage['DALF_KingdomTreasure'].number > 7;
                });
            }
        },
        "DALF_card_queen2_1": {
            equipSkill: true,
            mod: {
                cardEnabled: function (card, player) {
                    if (player.storage['DALF_KingdomTreasure'].number > 7 &&
                        card.name == 'DALF_card_forward') return false;
                },
                maxHandcard: function (player, num) {
                    return num + game.countPlayer(function (current) {
                        return current.storage['DALF_KingdomTreasure'].number > 7;
                    });
                }
            },
            inherit: "DALF_card_queen_1"
        },
        "DALF_card_queen_2": {
            equipSkill: true,
            enable: "chooseToUse",
            filter: function (event, player) {
                return player.hasCard(function (card) {
                    return card.name == 'DALF_card_forward';
                }, 'hs');
            },
            hiddenCard: function (player, name) {
                if (!player.hasCard(function (card) {
                    return card.name == 'DALF_card_forward';
                }, 'hs')) return false;
                let info = get.info({ name: name });
                return info && info.enable;
            },
            chooseButton: {
                dialog: function (event, player) {
                    let map = {};
                    for (let i = 0; i < lib.inpile.length; i++) {
                        if (!get.is.instantCard({ name: lib.inpile[i] })) continue;
                        let info = get.info({ name: lib.inpile[i] });
                        if (!info || !info.enable) continue;
                        if (info.selectTarget == -1 && !info.toself) continue;
                        let typex = get.type2(lib.inpile[i]);
                        if (!map[typex]) map[typex] = [];
                        if (event.filterCard({ name: lib.inpile[i] }, player, event))
                            map[typex].push([typex, '', lib.inpile[i]]);
                        if (lib.inpile[i] == 'sha') {
                            for (let j of lib.inpile_nature) {
                                if (event.filterCard({ name: lib.inpile[i], nature: j }, player, event)) map[typex].push(['basic', '', 'sha', j]);
                            }
                        }
                    }
                    let dialog = ui.create.dialog('女王', 'hidden');
                    for (let j in map) {
                        dialog.addText(get.translation(j));
                        dialog.add([map[j], 'vcard']);
                    }
                    return dialog;
                },
                check: function (button) {
                    if (button.link[2] == 'tiesuo') return 0;
                    let player = _status.event.player,
                        cardx = { name: button.link[2] };
                    let value = player.getUseValue(cardx, true, true);
                    if (get.tag(cardx, 'draw') > 1) value += 2;
                    if (get.tag(cardx, 'gain')) value += 1.1;
                    return value + (Math.random() * 5);
                },
                backup: function (links, player) {
                    return {
                        filterCard: { name: "DALF_card_forward" },
                        popname: true,
                        check: () => 1,
                        position: 'hs',
                        viewAs: { name: links[0][2], nature: links[0][3] }
                    };
                },
                prompt: function (links, player) {
                    return '将一张【前进】当做' + (get.translation(links[0][3]) || '') + '【' + get.translation(links[0][2]) + '】使用';
                }
            },
            ai: {
                order: 1,
                result: {
                    player: 1
                }
            },
        },
        "DALF_card_queen_3": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            content: function () {
                "step 0"
                event.cardx = player.storage['DALF_KingdomTreasure'];
                let hp = 2 - player.hp;
                if (hp > 0) player.recover(hp);
                event.isRelegate = true;
                if (event.cardx != undefined) {
                    let maxHp = event.cardx.storage.gainMaxHp - 1;
                    event.cardx.name = 'DALF_card_pawn';
                    event.cardx.number = 5;
                    event.cardx.storage.gainMaxHp = 1;
                    if (maxHp > 0) player.loseMaxHp(maxHp);
                    game.log(player, '的', '#g【女王】', '降格为了', '#g【士兵】');
                }
                "step 1"
                if (event.isRelegate && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.finish();
                card.init(card);
                "step 2"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    player.equip(event.cardx);
                }
            }
        },
        "DALF_card_queen2_3": {
            inherit: "DALF_card_queen_3",
            round: 2,
            content: function () {
                "step 0"
                let hp = 2 - player.hp;
                if (hp > 0) player.recover(hp);
            }
        },
        "DALF_card_king_1": {
            equipSkill: true,
            mod: {
                cardEnabled: function (card) {
                    if (card.name == 'DALF_card_forward') return false;
                }
            },
            trigger: {
                global: [
                    "loseAfter", "equipAfter", "addJudgeAfter",
                    "gainAfter", "loseAsyncAfter", "addToExpansionAfter"
                ]
            },
            forced: true,
            silent: true,
            filter: function (event, player) {
                return game.hasPlayer(function (current) {
                    let evt = event.getl(current);
                    return evt && evt.hs && evt.hs.length &&
                        evt.hs.some(card => (card.name == 'DALF_card_forward'));
                });
            },
            content: function () {
                "step 0"
                if (!player.storage['DALF_card_king_1'])
                    player.storage['DALF_card_king_1'] = 0;
                game.countPlayer(function (current) {
                    let evt = trigger.getl(current);
                    if (evt && evt.hs && evt.hs.length)
                        player.storage['DALF_card_king_1'] += evt.hs.filter(card => (card.name == 'DALF_card_forward')).length;
                });
                while (player.storage['DALF_card_king_1'] >= 2) {
                    player.draw();
                    player.storage['DALF_card_king_1'] -= 2;
                }
            }
        },
        "DALF_card_king_2": {
            equipSkill: true,
            enable: "phaseUse",
            filter: function (event, player) {
                return player.hasCard(function (card) {
                    return lib.skill['DALF_card_king_2'].filterCard(card, player);
                }, 'h');
            },
            filterCard: function (card, player) {
                return get.name(card) == 'DALF_card_forward' && player.canRecast(card);
            },
            discard: false,
            lose: false,
            delay: false,
            content: function () {
                "step 0"
                player.recast(cards);
                let cards2 = [];
                for (let i = 0; i < 2; i++) {
                    cards2.push(game.createCard2('DALF_card_forward'));
                    const p = Math.floor(Math.random() * ui.cardPile.childElementCount);
                    ui.cardPile.insertBefore(cards2[i], ui.cardPile.childNodes[p]);
                }
                player.$throw(cards2, 100);
            },
            ai: {
                order: 1,
                result: {
                    player: 1
                }
            }
        },
        "DALF_card_king_3": {
            equipSkill: true,
            trigger: { player: "dying" },
            forced: true,
            silent: true,
            content: function () {
                "step 0"
                event.cardx = player.storage['DALF_KingdomTreasure'];
                let hp = player.maxHp - player.hp;
                if (hp > 0) player.recover(hp);
                if (!player.hasSkill('DALF_luanzhou')) {
                    event.isRelegate = true;
                    if (event.cardx != undefined) {
                        let maxHp = event.cardx.storage.gainMaxHp;
                        event.cardx.name = 'DALF_card_pawn';
                        event.cardx.number = 1;
                        event.cardx.storage.gainMaxHp = 0;
                        if (maxHp > 0) player.loseMaxHp(maxHp);
                        game.log(player, '的', '#g【国王】', '降格为了', '#g【空无】');
                    }
                } else event.finish();
                "step 1"
                if (event.isRelegate && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.goto(3);
                event.cardx.init(event.cardx);
                "step 2"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    player.equip(event.cardx);
                }
                "step 3"
                event.players = game.filterPlayer(function (current) {
                    return current.storage['DALF_KingdomTreasure'].name == 'DALF_card_prince' &&
                        current.countCards('h');
                });
                if (event.players.length) {
                    player.draw();
                    player.chooseToCompare(event.targets).setContent('chooseToCompareMeanwhile');
                } else event.finish();
                "step 4"
                if (result.winner && result.winner !== player) {
                    event.isUpgrade = true;
                    event.target2 = result.winner;
                    if (event.cardx != undefined) {
                        event.cardx.name = 'DALF_card_king';
                        event.cardx.number = 13;
                        event.cardx.storage.gainMaxHp += 1;
                        event.cardx.init(event.cardx);
                        event.target2.gainMaxHp(1);
                        game.log(event.target2, '的', '#g【亲王】', '升变为了', '#g【国王】');
                    }
                } else event.finish();
                "step 5"
                if (event.isUpgrade && event.cardx != undefined) {
                    event.cardx.storage.isOnChanged = true;
                    game.cardsGotoOrdering(event.cardx);
                } else event.finish();
                card.init(card);
                "step 6"
                if (event.cardx != undefined) {
                    delete event.cardx.storage.isOnChanged;
                    event.target2.equip(event.cardx);
                }
            }
        }
    }
}